import mitmproxy
from mitmproxy import ctx, http
import os


class TestMapLocal:
    """
    测试MapLocal，修改股票名称
    """
    def request(self, flow: mitmproxy.http.HTTPFlow):
        if "v5/stock/batch/quote.json" in flow.request.pretty_url and "x=" in flow.request.pretty_url:
            with open(os.path.dirname(os.path.abspath(__file__))+"/quote.json", "r", encoding="utf8") as f:
                flow.response = http.Response.make(
                    200,
                    f.read(),
                    {"Content-Type": ":	application/json;charset=UTF-8"}
                )
        else:
            ctx.log(f"url: {flow.request.pretty_url}")


addons = [
    TestMapLocal()
]